

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

public class Demo {
   /* static String getUUID(String s){
        //
        System.out.println(s);
        String uuid = UUID.randomUUID().toString().replaceAll("-","").substring(0,18);
        s= uuid ;

        System.out.println(s);
        System.out.println(uuid);
        return s;
    }*/
/*

    static String getMD5(String str){
        try {
            //通过getInstance获取到一个MD5加密计算的对象
            MessageDigest md = MessageDigest.getInstance("MD5");
            //计算MD5函数
            md.update(str.getBytes());
            //此次百度的
            //digest()最后确定返回md5 hash值，返回值为8为字符串。因为md5 hash值是16位的hex值，实际上就是8位的字符

            String substring = UUID.randomUUID().toString().replaceAll("-", "").substring(16);
            return new BigInteger(1,md.digest()).toString(32)+substring;

        }catch (Exception e){

            return str;
        }

    }

*/
/*

    //encryption
    */
/**
     *  将字符串通过MD5得到计算后的MD5信息
     * @param str  字符串
     * @return
     *//*

    static String getMD5(String str){
        try {
            //通过getInstance获取到一个MD5加密计算的对象
            MessageDigest md = MessageDigest.getInstance("MD5");
            //计算MD5函数
            md.update(str.getBytes());
            //此处百度的
            //digest()最后确定返回md5 hash值，返回值为字符串。因为md5 hash值是16位的hex值，实际上就是8位的字符
            return new BigInteger(1,md.digest()).toString(32);
            //   105ism5b2p0tdpcio72kmi6irg

        }catch (Exception e){

            return str;
        }

    }

    static String generatePassword(String password){
        //获取随机生成的字符串
        String uuid = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 18);
        //获取到随机生成的uuid 和 通过MD5编译后的字符串
        password = getMD5(password + uuid);

        // password 【123】= 105ism5b2p0tdpcio72kmi6irg8e74b79f1e2c6b2b 密文
        char[] cs = new char[44];
        for (int i = 0; i < 48; i += 3) {
            cs[i] = password.charAt(i / 3 * 2);
            char c = uuid.charAt(i / 3);
            cs[i + 1] = c;
            cs[i + 2] = password.charAt(i / 3 * 2 + 1);
        }

        return new String(cs);

    }

    */
/**
     * 校验密码是否正确
     *//*

    public static boolean verify(String password, String md5) {
        char[] cs1 = new char[32];
        char[] cs2 = new char[16];
        for (int i = 0; i < 48; i += 3) {
            cs1[i / 3 * 2] = md5.charAt(i);
            cs1[i / 3 * 2 + 1] = md5.charAt(i + 2);
            cs2[i / 3] = md5.charAt(i + 1);
        }
        String salt = new String(cs2);
        return getMD5(password + salt).equals(new String(cs1));
    }



*/


    //encryption
/*

    */
/**
     * 生成随机字符18位
     *
     *//*

    static String generateUUID(){

        String uuid = UUID.randomUUID().toString().replaceAll("-","").substring(0,32);

        return uuid;
    }


    */
/**
     *
     *      MD5
     *
     *//*

    public static String getMD5(String password){
        try {

            MessageDigest md5 = MessageDigest.getInstance("MD5");

            byte[] bytes = md5.digest(password.getBytes("UTF-8"));

            StringBuilder sb = new StringBuilder();//   使用字符串拼接

            for (byte item:bytes) {
                sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
            }
            return sb.toString().toUpperCase();//将得到的md加密字符转成大写

        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
*/


    public static void main(String[] args) throws Exception {


/*

        String md51 = MD5UUIDUtils.getMD5("12345");
        System.out.println(md51);

        Boolean flig = MD5UUIDUtils.flig("12345", md51);

        System.out.println(flig);

*/

        //202cb962ac59075b964b07152d234b70
        //105ism5b2p0tdpcio72kmi6irg
        //105ism5b2p0tdpcio72kmi6irg
     /*   String uuid = getMD5("123");
        System.out.println(uuid);
*/
        //105ism5b2p0tdpcio72kmi6irg8e74b79f1e2c6b2b
/*

        boolean verify = verify("123", "105ism5b2p0tdpcio72kmi6irg8e74b79f1e2c6b2b");
        System.out.println(verify);
*/


      /*  boolean info = MD5Utils.info(s, "12387");
        System.out.println(info);*/
   /*     char[] cs = new char[44];
        for (int i = 0; i < 10; i++) {

        }*/

      /*  Scanner sc= new Scanner(System.in);
        int[] str1 = new int[10];
        for (int i = 0; i < 10; i++)
            str1[i] = i;

        String str2 = sc.nextLine();
        for (int j = 0; j < str2.length(); j++) {
            System.out.println(str2.charAt(j));
        }*/

   /*   String ss= "123456";
        String s = MD5Utils.generatePassword("123456");
      //  System.out.println(s); // e10adc3949ba59abbe56e057f20f883e
        String password = DigestUtils.md5DigestAsHex(ss.getBytes());//数据库保存的密码
        System.out.println(password);
        String pwd = "123456";
        String pwd2 = "111111";
        //使用md5验证
        System.out.println(DigestUtils.md5DigestAsHex(pwd.getBytes()).equals(password));
        System.out.println(DigestUtils.md5DigestAsHex(pwd2.getBytes()).equals(password));
    }*/

   /*     String md5 = MD5UUIDUtils.getMD5("123456");
        System.out.println(md5);
*/

      /*  String s = MD5Utils.generatePassword("123");
        System.out.println(s);*/
/*
        MD5Utils*/
    }


       /*
    //登录时，从页面获取密码与数据库密码进行比较，这里就不获取，直接定义
		String password = DigestUtils.md5DigestAsHex("123456".getBytes());//数据库保存的密码
		String pwd = "123456";//从页面获取的密码1
		String pwd2 = "111111";//从页面获取的密码2
		//使用md5验证
		System.out.println(DigestUtils.md5DigestAsHex(pwd.getBytes()).equals(password));
		System.out.println(DigestUtils.md5DigestAsHex(pwd2.getBytes()).equals(password));




    */

}
